Make ApplicationCertificateIdExtractor configurable via SPI#1280
Make ApplicationCertificateIdExtractor configurable via SPI#1280
Conversation
Motivation: The `ApplicationCertificateIdExtractor` was hardcoded to use `CommonNameExtractor`, which extracts the CN from the certificate's subject DN. Users who need to extract certificate IDs differently (e.g., from SANs or other DN fields) had no way to customize this behavior. Modifications: - Modified `ApplicationCertificateAuthorizer` to load `ApplicationCertificateIdExtractor` via `ServiceLoader`. Result: - You can now provide a custom `ApplicationCertificateIdExtractor` via SPI.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughSwitches certificate-ID extraction to a pluggable SPI via ServiceLoader, adds a test extractor and its SPI registration, introduces an integration test exercising mTLS with the custom extractor, and updates an integration test dependency. Changes
Sequence DiagramsequenceDiagram
participant Client as mTLS Client
participant Server as CentralDogma Server
participant Loader as ServiceLoader
participant Extractor as TestCertificateIdExtractor
participant Registry as AppIdentity Registry
Client->>Server: HTTPS request with client X.509 cert
rect rgba(100,150,200,0.5)
Server->>Loader: load(ApplicationCertificateIdExtractor)
Loader-->>Server: discover TestCertificateIdExtractor
end
rect rgba(150,180,220,0.5)
Server->>Extractor: extractCertificateId(certificate)
Extractor->>Extractor: parse subject CN -> "test-<CN>"
Extractor-->>Server: "test-my-client"
end
rect rgba(200,150,100,0.5)
Server->>Registry: lookup app identity "test-my-client"
Registry-->>Server: no identity / then identity + roles (after registration/grant)
Server-->>Client: 401 / 403 / 200 depending on registry state
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
server/src/main/java/com/linecorp/centraldogma/server/internal/api/auth/ApplicationCertificateAuthorizer.java (1)
77-79: Consider showing class names in the error message for easier debugging.The current message will print object references. Showing class names would help operators identify which implementations are conflicting.
♻️ Optional improvement for clearer error message
} else { throw new IllegalStateException( "Only one ApplicationCertificateIdExtractor implementation must be provided. " + - "found: " + extractors); + "found: " + extractors.stream() + .map(e -> e.getClass().getName()) + .collect(Collectors.toList())); }Add the import:
import java.util.stream.Collectors;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/src/main/java/com/linecorp/centraldogma/server/internal/api/auth/ApplicationCertificateAuthorizer.java` around lines 77 - 79, The IllegalStateException in ApplicationCertificateAuthorizer currently prints the extractors list (object references); update the throw to include the concrete class names of the conflicting ApplicationCertificateIdExtractor implementations by mapping extractors to their getClass().getName() (or similar) and joining them (e.g., using Collectors.joining) so the exception message shows the implementation class names rather than raw object toString() values; keep the same exception text but replace "found: " + extractors with the joined class-name string for easier debugging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@it/server/src/test/java/com/linecorp/centraldogma/it/CustomCertificateIdExtractorTest.java`:
- Around line 111-122: The ClientFactory created in configureWebClient(...) is
never closed; modify configureWebClient to assign the built ClientFactory to a
static field (e.g., private static ClientFactory clientFactory) instead of
passing an anonymous instance to builder.factory(...), import
org.junit.jupiter.api.AfterAll, and add an `@AfterAll` static teardown method that
checks for non-null clientFactory and calls clientFactory.close() (or
closeAsync().join() if async) to release native resources; update
WebClientBuilder usage to use the static clientFactory when calling
builder.factory(...).
---
Nitpick comments:
In
`@server/src/main/java/com/linecorp/centraldogma/server/internal/api/auth/ApplicationCertificateAuthorizer.java`:
- Around line 77-79: The IllegalStateException in
ApplicationCertificateAuthorizer currently prints the extractors list (object
references); update the throw to include the concrete class names of the
conflicting ApplicationCertificateIdExtractor implementations by mapping
extractors to their getClass().getName() (or similar) and joining them (e.g.,
using Collectors.joining) so the exception message shows the implementation
class names rather than raw object toString() values; keep the same exception
text but replace "found: " + extractors with the joined class-name string for
easier debugging.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7e500efa-0863-4fcf-b75d-0f0fd4fe8592
📒 Files selected for processing (5)
it/server/build.gradleit/server/src/test/java/com/linecorp/centraldogma/it/CustomCertificateIdExtractorTest.javait/server/src/test/java/com/linecorp/centraldogma/it/TestCertificateIdExtractor.javait/server/src/test/resources/META-INF/services/com.linecorp.centraldogma.server.auth.ApplicationCertificateIdExtractorserver/src/main/java/com/linecorp/centraldogma/server/internal/api/auth/ApplicationCertificateAuthorizer.java
Motivation:
The
ApplicationCertificateIdExtractorwas hardcoded to useCommonNameExtractor, which extracts the CN from the certificate's subject DN. Users who need to extract certificate IDs differently (e.g., from SANs or other DN fields) had no way to customize this behavior.Modifications:
ApplicationCertificateAuthorizerto loadApplicationCertificateIdExtractorviaServiceLoader.Result:
ApplicationCertificateIdExtractorvia SPI.